<template>
  <router-view />
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/src/message.scss'

import { initShowLogicEngine } from '@/management/hooks/useShowLogicEngine'

const store = useStore()
const router = useRouter()
const route = useRoute()

onMounted(async () => {
  
  store.commit('publishform/setFormId', route.params.id)

  try {
    await store.dispatch('publishform/init')
    await initShowLogicEngine(store.state.publishform.schema.logicConf.showLogicConf || {})
  } catch (err: any) {
    ElMessage.error(err.message)

    setTimeout(() => {
     router.replace({ name: 'forms' })
    }, 1000)
  }
})
</script>